// http://poj.org/problem?id=1577

#include <iostream>
#include <stack>
#include <string>
#include <queue>
using namespace std;


/*
BDHPY
CM
GQ
K
*
AC
B
$

KGCBDHQMPY
BAC

*/

typedef struct Node {
    char val;
    Node *left, *right;
} Node;

Node* insert(Node* root, char c) {
    if (!root) {
        Node* nd = new Node();
        nd->val = c;
        return nd;
    }

    if (c < root->val) {
        root->left = insert(root->left, c);
    } else {
        root->right = insert(root->right, c);
    }
    return root;
}

void preorder(Node* root) {
    if (root) {
        printf("%c", root->val);
        preorder(root->left);
        preorder(root->right);
    }
}

int main() {
    while (true) {
        stack<string> messages;
        string message;
        while (cin >> message && message != "*" && message != "$") {
            messages.push(message);
        }
        const char rootCh = messages.top()[0];
        messages.pop();
        Node* root = new Node();
        root->val = rootCh;
        while (!messages.empty()) {
            string msg = messages.top();
            messages.pop();
            for (int i = 0; i < msg.length(); i++) {
                root = insert(root, msg[i]);
            }
        }
        preorder(root);
        printf("\n");
        if (message == "$") {
            break;
        }
    }
    return 0;
}